/*
safty.h
offer agv car check abstacle on driving derection and deal with api
designed by lunanting

---------------------------
2020-05-25 10:11:26
create file
---------------------------
*/
#ifndef __SAFTY_H
#define __SAFTY_H

#include "../bsp/base_type.h"
#include "mag_navigation.h"

//safty sensor io 
#define SAFTY_SIDE_1 3  //侧面靠近车头 1号sensor
#define SAFTY_SIDE_2 4  //侧面靠近车尾 2号sensor
#define SAFTY_FW_1  5   //前进方向 1号sensor
#define SAFTY_FW_2  6   //前进方向 2号sensor
#define SAFTY_BK_1  7   //后退方向 1号sensor
#define SAFTY_BK_2  8   //后退方向 2号sensor

#define SAFTY_collision_io 10    //防撞条 io

#define SAFTY_stop_io   10   //stop motor power io

#define SAFTY_io_touch  0   //io 触发状态

//时间设定
#define SAFTY_touch_time    500     //时间触发 500ms
#define SAFTY_relase_touch_time     1000    //时间释放时间 1000ms

/********************data type define*********************/
//安全状态枚举
typedef enum{
    SAFTY_state_normal = 0,
    SAFTY_state_lidar_abnormal = 1,
    SAFTY_state_too_near = 2,
    SAFTY_state_obstacle = 3,
}SAFTY_STATE_E;

//雷达ROI枚举
typedef enum{
    LIDAR_roi_round = 1,    /* 绕边时的roi，横向范围[-6cm, 50cm]，垂直范围[0cm, 160cm]，输出限制在[75cm, 130cm] */
    LIDAR_roi_leave = 2,    /* 离车或原地旋转时的roi，横向范围[0cm, 5cm]，垂直范围[0cm, 160cm]，输出范围[0cm, 160cm] */
    LIDAR_roi_obstacle = 3  /* 避障时的roi，横向范围[0cm, 25cm]，垂直范围[0cm, 65cm]，输出范围[0cm, 65cm] */
}LIDAR_ROI_E;

//safty class
typedef struct{
    u8 init;    //module init state,1=inited
    u8 fw;  //forward sensor state ,1=touched
    u8 bk;  //back sensor touch state,1=touched
    u8 conllision;  //conllision
}SAFTY_class;


/*************************function extern********************/
extern void xp_safty_init(void);    //safty mode init
extern SAFTY_STATE_E xp_safty_check(uint8_t lidar_roi, int32_t obstacle_dist);   //check safty state


#endif
//end of the file

